package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.utils.Content;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class VideoLibraryAdapter extends StkProviderMultiAdapter<String> {


    public VideoLibraryAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new VideoLibraryProvider());
    }

    private class VideoLibraryProvider extends BaseItemProvider<String> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_video_library;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, String bean) {
            if (baseViewHolder.getBindingAdapterPosition() == 0) {
                baseViewHolder.getView(R.id.ivVideoLibraryItemPrivacy).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemAdd).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.rlVideoLibraryItemIcon).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemEdit).setVisibility(View.VISIBLE);
            } else if (bean.isEmpty()) {
                baseViewHolder.getView(R.id.ivVideoLibraryItemPrivacy).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemAdd).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.rlVideoLibraryItemIcon).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemEdit).setVisibility(View.INVISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivVideoLibraryItemPrivacy).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemAdd).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.rlVideoLibraryItemIcon).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivVideoLibraryItemEdit).setVisibility(View.VISIBLE);
                String path = PathUtils.getFilesPathExternalFirst() + Content.myVideo;
                List<File> data = FileUtils.listFilesInDir(path + "/" + bean);
                if (data != null && data.size() > 0) {
                    baseViewHolder.setImageResource(R.id.ivVideoLibraryItemIcon, R.drawable.awodeyingpian);
                    Glide.with(baseViewHolder.itemView).load(data.get(0).getPath()).into((ImageView) baseViewHolder.getView(R.id.ivVideoLibraryItemImg));
                } else {
                    baseViewHolder.setImageResource(R.id.ivVideoLibraryItemIcon, R.drawable.akongdie);
                }
                baseViewHolder.setText(R.id.tvVideoLibraryItemName, bean);
            }
        }
    }

}
